package com.kaiwukj.android.ufamily.mvp.ui.page.home.home;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.flyco.tablayout.listener.CustomTabEntity;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.app.base.review.BaseFragment;
import com.kaiwukj.android.ufamily.mvp.ui.page.home.home.active.ActiveFragment;
import com.kaiwukj.android.ufamily.mvp.ui.widget.KaiwuTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class HomeContainerL2Fragment extends BaseFragment {

    private int pos;

    @BindView(R.id.tab)
    KaiwuTabLayout tabLayout;

    /*@BindView(R.id.vp_content)
    ViewPager2 viewPager;*/

    public static HomeContainerL2Fragment newInstance(int pos) {
        Bundle bundle = new Bundle();
        bundle.putInt("pos", pos);
        HomeContainerL2Fragment fragment = new HomeContainerL2Fragment();
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        pos = getArguments().getInt("pos");
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_home_container_l2;
    }

    @Override
    protected void initView() {

        ArrayList<Fragment> fragments = new ArrayList<>();
       // fragments.add(HomeV20Fragment.newInstance(pos, 0));
       // fragments.add(HomeV20Fragment.newInstance(pos, 1));
        fragments.add(ActiveFragment.newInstance(pos));

        List<String> titles = new ArrayList<>();
        titles.add("探索");
        titles.add("关注");
        titles.add("活动");

        ArrayList<CustomTabEntity> tabEntities = new ArrayList<>();
        for (String title : titles) {
            tabEntities.add(new CustomTabEntity() {
                @Override
                public String getTabTitle() {
                    return title;
                }

                @Override
                public int getTabSelectedIcon() {
                    return 0;
                }

                @Override
                public int getTabUnselectedIcon() {
                    return 0;
                }
            });
        }

        tabLayout.setTabData(tabEntities, getChildFragmentManager(), R.id.fl_content, fragments);
        tabLayout.setCurrentTab(0);




      /*  viewPager.setOffscreenPageLimit(fragments.size());

        viewPager.setAdapter(new FragmentStateAdapter(this) {
            @NonNull
            @Override
            public Fragment createFragment(int position) {
                return fragments.get(position);
            }

            @Override
            public int getItemCount() {
                return fragments.size();
            }

            @Override
            public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
                super.onDetachedFromRecyclerView(recyclerView);
                LogUtils.d("--------onDetachedFromRecyclerView---------");
            }
        });

        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                View view = LayoutInflater.from(getContext())
                        .inflate(R.layout.weight_item_home_tab_l2_selected, null);
                TextView title = view.findViewById(R.id.tv_title);
                title.setText(tab.getText());
                tab.setCustomView(view);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });


        new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
            tab.setText(titles.get(position));
        }).attach();*/

    }

    @Override
    protected void initData(Bundle savedInstanceState) {
    }
}
